package com.raycloud.erp.omll.provider.constant;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 枫伦
 * @description: TODO
 * @date 2020/10/23 1:53 下午
 */
@Component
public class OmallTradeStatus {

    private static final String SPLIT_CHAR = "_";

    /**
     * 未发货
     */
    public static final String OMALL_TRADE_UNSHIPPED = "unshipped";

    /**
     * 已发货
     */
    public static final String OMALL_TRADE_ALLSHIPPED = "allshipped";
    /**
     * 部分发货
     */
    public static final String OMALL_TRADE_PARTIALSHIPPED = "partialshipped";

    /**
     * 全部退款
     */
    public static final String OMALL_RETURN_WHOLE = "whole";
    /**
     * 部分退款
     */
    public static final String OMALL_RETURN_PART = "part";


    public Map<String, TradeStatus> getMap() {
        Map<String, TradeStatus> map = new HashMap<String, TradeStatus>(16, 1);
        //未发货
        map.put(getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, null, null),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, null, null),
                        ErpStatusConstant.TbTradeStatus.SYS_STATUS_WAIT_AUDIT, 1));
        //未发货 & 部分退款  --应该不存在
        map.put(getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_PART, null),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_PART, null),
                        ErpStatusConstant.TbTradeStatus.SYS_STATUS_WAIT_AUDIT, 1));
        //未发货 & 部分退款 & 待审核
        map.put(getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_WAIT),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_WAIT),
                        ErpStatusConstant.TbTradeStatus.SYS_STATUS_WAIT_AUDIT, 1));

        //未发货 & 部分退款 & 审核通过
        map.put(getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_PASSED),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_PASSED),
                        ErpStatusConstant.TbTradeStatus.SYS_STATUS_WAIT_AUDIT, 1));

        //未发货 && 全部退款 --应该不存在
        map.put(getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_WHOLE, null),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_WHOLE, null),
                        ErpStatusConstant.TbTradeStatus.SYS_STATUS_WAIT_AUDIT, 1));

        //未发货 && 全部退款 && 待审核
        map.put(getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_WAIT),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_WAIT),
                        ErpStatusConstant.TbTradeStatus.SYS_STATUS_WAIT_AUDIT, 1));

        //未发货 && 全部退款 && 审核通过
        map.put(getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_PASSED),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_PASSED),
                        ErpStatusConstant.TbTradeStatus.SYS_STATUS_CLOSED, 5));

        //未发货 && 全部退款 && 审核不通过
        map.put(getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_NOT_PASSED),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_UNSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_NOT_PASSED),
                        ErpStatusConstant.TbTradeStatus.SYS_STATUS_WAIT_AUDIT, 1));


        //部分发货
        map.put(getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, null, null),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, null, null),
                        ErpStatusConstant.TbTradeStatus.SYS_STATUS_WAIT_AUDIT, 1));

        //部分发货 && 部分退款 && 待审核
        map.put(getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_WAIT),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_WAIT),
                        ErpStatusConstant.TbTradeStatus.SYS_STATUS_WAIT_AUDIT, 1));

        //部分发货 && 部分退款 && 审核通过
        map.put(getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_PASSED),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_PASSED),
                        ErpStatusConstant.TbTradeStatus.SYS_STATUS_WAIT_AUDIT, 1));

        //部分发货 && 部分退款 && 审核不通过
        map.put(getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_NOT_PASSED),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_NOT_PASSED),
                        ErpStatusConstant.TbTradeStatus.SYS_STATUS_WAIT_AUDIT, 1));

        //部分发货 && 全部退款  --应该不存在
        map.put(getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_WHOLE, null),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_WHOLE, null), ErpStatusConstant.TbTradeStatus
                        .SYS_STATUS_WAIT_AUDIT, 1));

        //部分发货 && 全部退款 && 待审核
        map.put(getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_WAIT),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_WAIT), ErpStatusConstant.TbTradeStatus
                        .SYS_STATUS_WAIT_AUDIT, 1));
        //部分发货 && 全部退款 && 审核通过
        map.put(getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_PASSED),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_PASSED), ErpStatusConstant.TbTradeStatus
                        .SYS_STATUS_CLOSED, 5));
        //部分发货 && 全部退款 && 审核不通过
        map.put(getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_NOT_PASSED),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_PARTIALSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_NOT_PASSED), ErpStatusConstant.TbTradeStatus
                        .SYS_STATUS_WAIT_AUDIT, 1));

        // 全部发货
        map.put(getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, null, null),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, null, null), ErpStatusConstant.TbTradeStatus
                        .SYS_STATUS_FINISHED, 4));

        // 全部发货 && 部分退款 && 待审核
        map.put(getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_WAIT),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_WAIT), ErpStatusConstant.TbTradeStatus.SYS_STATUS_SELLER_SEND_GOODS, 4));
        // 全部发货 && 部分退款 && 审核通过
        map.put(getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_PASSED),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_PASSED), ErpStatusConstant.TbTradeStatus
                        .SYS_STATUS_SELLER_SEND_GOODS, 4));
        // 全部发货 && 部分退款 && 审核不通过
        map.put(getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_NOT_PASSED),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_PART, OmallRefundStatus.REFUND_STATUS_NOT_PASSED), ErpStatusConstant.TbTradeStatus
                        .SYS_STATUS_SELLER_SEND_GOODS, 4));

        // 全部发货 && 全部退款
        map.put(getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_WHOLE, null),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_WHOLE, null), ErpStatusConstant.TbTradeStatus
                        .SYS_STATUS_FINISHED, 4));

        // 全部发货 && 全部退款 && 待审核
        map.put(getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_WAIT),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_WAIT), ErpStatusConstant.TbTradeStatus
                        .SYS_STATUS_SELLER_SEND_GOODS, 4));
        // 全部发货 && 全部退款 && 审核通过
        map.put(getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_PASSED),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_PASSED), ErpStatusConstant.TbTradeStatus
                        .SYS_STATUS_CLOSED, 5));

        // 全部发货 && 全部退款 && 审核不通过
        map.put(getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_NOT_PASSED),
                new TradeStatus(OmallTradeStatus.getTradeStatusMapKey(OMALL_TRADE_ALLSHIPPED, OMALL_RETURN_WHOLE, OmallRefundStatus.REFUND_STATUS_NOT_PASSED), ErpStatusConstant.TbTradeStatus
                        .SYS_STATUS_SELLER_SEND_GOODS, 4));

        return map;
    }

    /**
     * 订单发货状态 + 订单退款状态 + 自订单退款状态
     *
     * @param tradeStatus
     * @param omallTradeReturnStatus
     * @param orderRefundStatus
     * @return
     */
    public static String getTradeStatusMapKey(String tradeStatus, String omallTradeReturnStatus, String orderRefundStatus) {
        StringBuilder key = new StringBuilder(Constants.SOURCE).append(SPLIT_CHAR).append(tradeStatus);
        if (StringUtils.isNotEmpty(omallTradeReturnStatus)) {
            key.append(SPLIT_CHAR).append(omallTradeReturnStatus);
        }
        if (StringUtils.isNotEmpty(orderRefundStatus)) {
            key.append(SPLIT_CHAR).append(orderRefundStatus);
        }
        return key.toString();
    }
}
